/********************************************************************
FileName    :   Bll_cktz.cs
CreateTime  :   2015-10-15 10:10
BaseClass   :   Bll_cktz
FileType    :   .cs
Author      :  minjie
Description :   Bll_cktzBLL层（简单三层）
*********************************************************************/

using System;
using System.Text;
using System.Collections.Generic;

using System.Data;
using OS.Common;
using OS.DAL;
namespace OS.BLL
{
    /// <summary>
    /// Bll_cktz的摘要说明。
    /// </summary>
    public partial class Bll_cktz
    {

        private readonly Dal_cktz dal = new Dal_cktz();
        public Bll_cktz()
        { }

        #region  Method
        /// <summary> 
        /// 增加一条数据 
        /// </summary> 
        public bool Add(cktz_Entity model)
        {
            return dal.Add(model);
        }

        /// <summary> 
        /// 增加一条数据 
        /// </summary> 
        public string AddStr(cktz_Entity model)
        {
            return dal.AddStr(model);
        }

        /// <summary> 
        /// 更新一条数据 
        /// </summary> 
        public bool Update(cktz_Entity model)
        {
            return dal.Update(model);
        }

        /// <summary> 
        /// 删除一条数据 
        /// </summary> 
        public bool Delete(string bmh)
        {

            return dal.Delete(bmh);
        }
        /// <summary> 
        /// 批量删除一批数据 
        /// </summary> 
        public bool DeleteList(string bmhlist)
        {
            return dal.DeleteList(bmhlist);
        }
        /// <summary> 
        /// 得到一个对象实体 
        /// </summary> 
        public cktz_Entity GetModel(string bmh)
        {

            return dal.GetModel(bmh);
        }

        /// <summary> 
        /// 获得数据列表 
        /// </summary> 
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary> 
        /// 获得前几行数据 
        /// </summary> 
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary> 
        /// 获得数据列表 
        /// </summary> 
        public List<cktz_Entity> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary> 
        /// 获得数据列表 
        /// </summary> 
        public List<cktz_Entity> GetModelList(string strWhere, string orderby, int startIndex, int endIndex)
        {
            DataSet ds = dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List<cktz_Entity> GetModelList(int pageIndex, int pageSize,string strWhere)
        {
            DataSet ds = dal.GetListByPage(pageIndex, pageSize,strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary> 
        /// 获得数据列表 
        /// </summary> 
        public List<cktz_Entity> DataTableToList(DataTable dt)
        {
            List<cktz_Entity> modelList = new List<cktz_Entity>();
            if (dt != null)
            {
                int rowsCount = dt.Rows.Count;
                if (rowsCount > 0)
                {
                    cktz_Entity model;
                    for (int n = 0; n < rowsCount; n++)
                    {
                        model = new cktz_Entity();
                        if (dt.Rows[n]["rq"] != null && dt.Rows[n]["rq"].ToString() != "")
                        {
                            model.rq = DateTime.Parse(dt.Rows[n]["rq"].ToString());
                            model.rq2 = model.rq.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        model.bmh = dt.Rows[n]["bmh"].ToString();
                        model.pzh = dt.Rows[n]["pzh"].ToString();
                        model.spbh = dt.Rows[n]["spbh"].ToString();
                        if (dt.Rows[n]["sl"] != null && dt.Rows[n]["sl"].ToString() != "")
                        {
                            model.sl = decimal.Parse(dt.Rows[n]["sl"].ToString());
                        }
                        if (dt.Rows[n]["dj"] != null && dt.Rows[n]["dj"].ToString() != "")
                        {
                            model.dj = decimal.Parse(dt.Rows[n]["dj"].ToString());
                        }
                        model.czy = dt.Rows[n]["czy"].ToString();
                        model.mem = dt.Rows[n]["mem"].ToString();
                        model.cklx = dt.Rows[n]["cklx"].ToString();
                        model.xh = dt.Rows[n]["xh"].ToString();
                        model.cgd_pzh = dt.Rows[n]["cgd_pzh"].ToString();
                        if (dt.Rows[n]["bj"] != null && dt.Rows[n]["bj"].ToString() != "")
                        {
                            model.bj = int.Parse(dt.Rows[n]["bj"].ToString());
                        }
                        if (dt.Rows[n]["csbj"] != null && dt.Rows[n]["csbj"].ToString() != "")
                        {
                            model.csbj = int.Parse(dt.Rows[n]["csbj"].ToString());
                        }

                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary> 
        /// 获得数据列表 
        /// </summary> 
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary> 
        /// 获取记录总数 
        /// </summary> 
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        #endregion
        #region 扩展方法
        public int Update(List<cktz_Entity> ls)
        {
            return dal.Update(ls);
        }
        #endregion
    }

}
